package com.jiazhong.example.project.bookstore.front.controller;

import com.jiazhong.example.project.bookstore.commons.bean.Alipay;
import com.jiazhong.example.project.bookstore.commons.util.JsonResult;
import com.jiazhong.example.project.bookstore.commons.util.ResultTool;
import com.jiazhong.example.project.bookstore.front.service.AlipayService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/alipay")
public class AlipayController {

    @Resource
    private AlipayService alipayService;

    private String orderId, logisticsId;

    @GetMapping("/pay")
    public String pay(Alipay alipay, String logisticsId) {
        this.orderId = alipay.getOut_trade_no();
        this.logisticsId = logisticsId;
        return alipayService.pay(alipay, logisticsId);
    }

    @GetMapping("/success")
    public JsonResult success() {
        return alipayService.query(this.orderId, this.logisticsId);
    }
}
